<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>公告列表</title>
    <link rel="stylesheet" href="../../../css/aui.css">
    <link rel="stylesheet" href="../../../script/widget/Zepto/dropload.css">
    <link rel="stylesheet" href="../../../css/index/notice_list.css">
</head>
<body>
    <div class="aui-content aui-margin-b-15" id="notice">
      <ul class="aui-list aui-media-list" id="notice_list">

      </ul>
    </div>
</body>
</html>
<script src="../../../script/aui/api.js"></script>
<script src="../../../script/extend/jquery-3.3.1.min.js"></script>
<script src="../../../script/aui/aui-slide.js"></script>
<script src="../../../script/common.js"></script>
<script src="../../../script/config.js"></script>
<script src="../../../script/widget/Zepto/dropload.min.js"></script>
<script>
    $(function(){
        page = get_curr_page();
        $('#notice').dropload({
            scrollArea: window,
            domDown: {
                domNoData: '<div class="dropload-noData">已经到底了</div>'
            },
            loadDownFn: function (me) {
                $.ajax({
                    type: 'GET',
                    url: Config.common.getNotice,
                    data: {page: get_curr_page()},
                    dataType: 'json',
                    success: function (data) {
                        if (data.code == 1) {
                            //判断是否是最后一页
                            var res = data.data;
                            if (res.length < 10 && res.length > 0) {
                                create_list(data);
                                me.lock();
                                me.noData();
                                me.resetload();
                            } else if (res.length == 0) {
                                me.lock();
                                me.noData();
                                me.resetload();
                            } else {
                                create_list(data);
                                me.resetload();
                            }
                        }
                    },
                    error: function (xhr, type) {
                        // 即使加载出错，也得重置
                        me.resetload();
                    }
                });
            }
        });
    });

     /*创建列表*/
     function create_list(ret){
         var data = ret.data;
         var html = '';
         $.each(data, function(index, val){
             html += '<li class="aui-list-item aui-margin-t-10"><div class="list-item-text aui-ellipsis-3">'+val.content+'</div><div class="aui-list-date">'+val.create_time+'</div></li>';
         });

         $("#notice_list").append(html)
     }

    /*获取系统公告列表*/
    function get_notice_list() {
        var param={};
        param.url = Config.common.getNotice;
        param.data = {};
        ajax(param,function(ret){
            if(ret.code == 1) {
                $("#notice_list").empty();
                create_list(page);
            } else {
                layer.msg(ret.msg);
            }
        })
    }

    /*获取当前页码*/
    function get_curr_page(){
        page = 0;
        var count = $('#notice_list li').length;
        if (count != 0) {
            //计算当前页码
            page = Math.ceil(count / 10);
        }
        return page;
    }

</script>
